#!/bin/bash
# Source tutorial run functions
. $WM_PROJECT_DIR/bin/tools/RunFunctions

# this script grabs all of the time info from the log files to build the performance information from the test cases
#  so far it doesnt pull out nicely formatted results. it needs some help

#table column names
echo solver N PreSolveTime PreSolveClockTime Initialresidual Finalresidual NoIterations PostSolveTime PostSolveClockTime TotalExecutionTime TotalClockTime

cd cufflink
log='log.testCufflinkFoam'

for solver in cufflink_CG cufflink_DiagPCG cufflink_SmAPCG cufflink_CG_Parallel cufflink_DiagPCG_Parallel cufflink_SmAPCG_Parallel
do
    cd $solver

    for j in N10 N50 N100 N500 N1000 N2000
        do
            cd $j
            echo -n $solver ${j:1}
            if [ -f $log ]
            then
                grep 'FOAM FATAL ' $log    #catch fatal errors
                grep 'PreSolveTime =' $log | awk '{printf " %s %s ",$3,$7}'
                grep 'Solving for T' $log | awk -F'[, ]' '{printf "%s %s %s ",$10,$15,$19}'
                grep 'PostSolveTime =' $log | awk '{printf "%s %s ",$3,$7}'
                grep 'TotalExecutionTime =' $log | awk '{printf "%s %s",$3,$7}'i
		echo ''
            else 
                echo "Test not run"
            fi
        cd ..
    done

    cd ..
done

cd ../OpenFOAM

for solver in CG DPCG DPCG-parallel4 DPCG-parallel6 GAMG GAMG6
do
    cd $solver

    for j in N10 N50 N100 N500 N1000 N2000
        do
            cd $j
            echo -n $solver ${j:1}
            if [ -f $log ]
            then
                grep 'FOAM FATAL ' $log    #catch fatal errors
                grep 'PreSolveTime =' $log | awk '{printf " %s %s ",$3,$7}'
                grep 'Solving for T' $log | awk -F'[, ]' '{printf "%s %s %s ",$10,$15,$19}'
                grep 'PostSolveTime =' $log | awk '{printf "%s %s ",$3,$7}'
                grep 'TotalExecutionTime =' $log | awk '{printf "%s %s",$3,$7}'i
                echo ''
            else
                echo " Test not run "
            fi
        cd ..
    done
    cd ..
done

cd ..

